/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = wtc_tcb_tdomtran.c                                 */
/*  NOTE      =                                                    */
/*  DATE      = 2015/08/26 by songbb                               */
/*******************************************************************/

#include "conntrack.h"

#include "../wtc_core.h"
#include "../wtc_comm.h"
#include "../wtc_mar.h"
#include "wtc_tcb_tdomtran.h"

int wtc_tcb_tdomtran_tmpostrecv(Conntrack *p_st_conn
                                , Apm_packet *p_analyze_in
                                , L7session_wtc *p_st_sess
                                , L7_wtc_packet *p_st_wtc_packet
                                , int i_recv_size
                                , int i_hint_index)
{
    char p_scratch[150] = {'\0'};
    char *p_domtran_nwtranidparent = NULL;
    unsigned int ui_service_len = 0;
    unsigned int ui_domtran_trantimeout = 0;
    unsigned int ui_domtran_nwtranidlen = 0;
    char p_domtran_nwtranidid[32] = {'\0'};
    int i_lcv;
    unsigned int ui_tmp = 0;

    if (bytebuff_get_int(p_st_wtc_packet->p_st_packet, 4, &ui_domtran_trantimeout, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;
    if (bytebuff_get_int(p_st_wtc_packet->p_st_packet, 4, &ui_domtran_nwtranidlen, BYTE_BIG_ENDIAN) != FR_SUCC)
        goto error;
    if (bytebuff_skip(p_st_wtc_packet->p_st_packet, 8) != FR_SUCC)
        goto error;

    for (i_lcv = 0; i_lcv < 32; i_lcv++)
    {
        if (bytebuff_get_int(p_st_wtc_packet->p_st_packet, 4, &ui_tmp, BYTE_BIG_ENDIAN) != FR_SUCC)
            goto error;
        p_domtran_nwtranidid[i_lcv] = (char) ui_tmp;
    }
    for (; i_lcv < 32; i_lcv++)
    {
        p_domtran_nwtranidid[i_lcv] = 0;
        if (bytebuff_skip(p_st_wtc_packet->p_st_packet, 4) != FR_SUCC)
            goto error;
    }
    ui_domtran_nwtranidlen = 32;
    if (wtc_mar_decode_string(p_st_sess, p_scratch, 150, p_st_wtc_packet, &p_domtran_nwtranidparent, &ui_service_len) != FR_SUCC)
        goto error;
    WTC_PRINT_FATAL("p_domtran_nwtranidparent:[%s]\n", p_domtran_nwtranidparent);

    wtc_free((void **) &p_domtran_nwtranidparent);
    return FR_SUCC;
error:
    wtc_free((void **) &p_domtran_nwtranidparent);
    return FR_FAIL;
}

int wtc_tcb_tdomtran_tmpostrecv_fad(char *p_payload
                                    , unsigned int ui_payload_len
                                    , unsigned int *p_ui_offset
                                    , int *p_i_direction
                                    , int i_recv_size
                                    , int i_hint_index)
{
    if (wtc_skip(p_payload, ui_payload_len, p_ui_offset, 4 + 4 + 8 + 32 * 4 + 32 * 4) != FR_SUCC)
        goto error;
    if (wtc_skip_string(p_payload, ui_payload_len, p_ui_offset) != FR_SUCC)
        goto error;
    return FR_SUCC;
error:
    return FR_FAIL;
}
